[java] Fix duplicate field name handling in InstanceCoercer#getFieldWriters#17187
Conversation
Review Summary by QodoFix duplicate field name handling in InstanceCoercer#getFieldWriters
WalkthroughsDescription• Fixes duplicate field name handling in InstanceCoercer#getFieldWriters • Adds merge function to Collectors.toMap() to retain first entry • Uses LinkedHashMap to preserve field processing order • Prevents runtime IllegalStateException on duplicate keys File Changes1. java/src/org/openqa/selenium/json/InstanceCoercer.java
|
Code Review by Qodo
1.
|
|
Hi maintainers, could someone please assign a reviewer for this PR? Thank you. |
💥 What does this PR do?
This PR fixes duplicate field name handling in
InstanceCoercer#getFieldWriters.Previously, field writers were collected using
Collectors.toMap(...)without an explicit merge strategy. When duplicate field names were encountered (for example through field hiding in inheritance), the collector would fail with an implicitIllegalStateExceptioncaused by duplicate keys.This change makes duplicate handling explicit by detecting duplicates during map collection and throwing a
JsonExceptionwith a clear error message.This prevents ambiguous field mappings and replaces the implicit collector failure with a controlled and descriptive exception.
🔧 Implementation Notes
The change modifies the
Collectors.toMap(...)call ingetFieldWriters.Previous behavior
Collectors.toMapwas used without a merge function.IllegalStateExceptionfrom the collector.New behavior
JsonExceptionwhen duplicate field names are encountered.Example scenario that previously caused an implicit collector failure: